package cn.yuanqiao.web.controller.archive.Identify;/**
 * @author 赵常飞
 * @date 2023/7/10 10:16
 */

import cn.yuanqiao.archive.Identify.domain.YqMjApprove;
import cn.yuanqiao.archive.Identify.service.BgqxLcIdentifyService;
import cn.yuanqiao.archive.Identify.service.IMjIdentifyService;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.web.page.TableDataInfo;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 流程引擎  保管期限鉴定
 *
 * @param
 * @author hbWang
 * @date 2023/12/6 10:55
 * @return
 */
@RestController
@RequestMapping("/archive/lc/bgqx/identify")
public class BgqxLcIdentifyController extends BaseController {
    @Autowired
    private BgqxLcIdentifyService identifyService;

    @Autowired
    private IMjIdentifyService mjIdentifyService;

   // @PreAuthorize("@ss.hasPermi('archive:bgqxidentify:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody JSONObject json) {
        List<Map<String, Object>> list = mjIdentifyService.getlist(json,"2");
        return getDataTable(list);
    }

    /**
     * 审批通过后修改密级状态
     *
     * @param id
     * @return
     */
    @Log(title = "保管期限审批通过", businessType = BusinessType.UPDATE)
    @PutMapping("/update/pass/state")
    public AjaxResult updateBgqxType(@RequestBody String id) {
        return toAjax(identifyService.updateBgqxType(id));
    }

    /**
     * 保管期限审批不通过
     *
     * @param id
     * @return
     */
    @Log(title = "保管期限审批不通过", businessType = BusinessType.UPDATE)
    @PutMapping("/update/disagree/state")
    public AjaxResult disagreeBgqxType(@RequestBody String id) {
        return toAjax(identifyService.disagreeBgqxType(id));
    }

    /**
     * 取消保管期限审批
     *
     * @param id
     * @return
     */
    @Log(title = "取消保管期限审批", businessType = BusinessType.UPDATE)
    @PutMapping("/cancel/approval")
    public AjaxResult cancelApproval(@RequestBody String id) {
        return toAjax(identifyService.cancelApproval(id));
    }

    /**
     * 查询审批详情
     *
     * @param id
     * @return
     */
    @Log(title = "查询审批详情", businessType = BusinessType.UPDATE)
    @PostMapping("/initiate/approval")
    public AjaxResult initiateApproval(@RequestBody String id) {
        return AjaxResult.success(identifyService.initiateApproval(id));
    }

    /**
     * 查询审批详情
     *
     * @param instanceId
     * @return
     */
    @PostMapping("/initiate/getInfoByInstanceId/{instanceId}")
    public AjaxResult getInfoByInstanceId(@PathVariable("instanceId") String instanceId) {
        YqMjApprove yqMjApproveByInstanceId = identifyService.getYqBgqxApproveByInstanceId(instanceId);
        return AjaxResult.success(identifyService.initiateApproval(yqMjApproveByInstanceId.getId()));

    }

    /**
     * 添加到保管期限审批
     *
     * @param yqMjApprove
     * @return
     */
    @PreAuthorize("@ss.hasPermi('archive:bgqxidentify:cancelApproval')")
    @Log(title = "添加到保管期限审批", businessType = BusinessType.INSERT)
    @PostMapping("/cancel/approval")
    public AjaxResult cancelApproval(@RequestBody List<YqMjApprove> yqMjApprove) {
        return toAjax(identifyService.insBgqxType(yqMjApprove));
    }

    /**
     * 查询保管期限审批列表
     *
     * @param yqMjApprove
     * @return
     */
    @PreAuthorize("@ss.hasPermi('archive:bgqxidentify:approveList')")
    @PostMapping("/approve/list")
    public TableDataInfo YqBgqxApproveList(@RequestBody YqMjApprove yqMjApprove) {
        startPage();
        List<YqMjApprove> list = identifyService.YqBgqxApproveList(yqMjApprove);
        return getDataTable(list);
    }

}
